
var catagoryName = ["news","music","shop","market","edu","livetv","vctv","tvradiop","vod","launcher","errorreport"]; //"dangtv",
var auto_select_true;
var all_read = true;
var wae_httpobj=null;

var intent_obj = null;
var netManager_obj = null;



function formaturl(_url){
	
	if(_url==''){
		return '';	
	}
	var fullurl;
	
	
	if(/(http\:\/\/[^\/]*)/.test(_url)==true){
		fullurl= _url;	
	}else{
		fullurl = "http://"+_url;	
	}
	
	if(/.*\/$/.test(_url)==true){
		fullurl = fullurl;	
	}else{
		fullurl = fullurl+'/';
	}
	
	return 	fullurl;	
}

function waeload(){
	
	var inputMainvalue = document.getElementById('MainhostIdNew').innerHTML;
	if(inputMainvalue==''){
		//var msg = "请填写服务器地址！";
		//openMessage(msg);
		return;
	}
	
	var main_host_url = formaturl(inputMainvalue);
	var returnUrl = main_host_url+'return.php';
	var returnCon = wae_httpobj.getWithSync(returnUrl,10,'utf-8');
	
	if(returnCon!=1){
		var msg = '服务器地址验证失败,是否保存?'
		if(window.confirm(msg)){
			
			waeparams.addContentProviderPersistenceWithAutoCommit("mainhosturl" , main_host_url) ;
			saveServer();
		}
	
	}else{
		waeparams.addContentProviderPersistenceWithAutoCommit("mainhosturl" , main_host_url) ;
		for(var i=0;i<catagoryName.length;i++){
			waeparams.addContentProviderPersistenceWithAutoCommit(catagoryName[i] , main_host_url) ;
		}
		saveServer()
	}
}



//保存地址
function saveServer(){
	try{
		waeparams.addContentProviderPersistenceWithAutoCommit("readwrite" , "1") ;
		var msg = "保存成功,请重新启动系统！";
		openMessage(msg);
	
	}catch(e){
		
	}
		
}


var m_returnCallback = null;
function openMessage(msg){
	m_returnCallback=null;
	if(arguments.length>1&&arguments[1])
		m_returnCallback = arguments[1];
	alert(msg);
}



function $(str) { return document.getElementById(str)}

function initId(){
	var catagory = document.getElementById("contentId").getElementsByTagName("input");
	for(var i=0;i<catagory.length;i++){
		var iid = catagoryName[i]+"Id";
		catagory.item(i).setAttribute("id",iid);
	}
}




function init(){
	
	var main_hosturl = waeparams.getContentProviderPersistence("mainhosturl") ;
	
	if(main_hosturl){
		document.getElementById('MainhostIdNew').innerHTML = main_hosturl;	
		
		for(var i=0;i<catagoryName.length;i++){
			var iid = catagoryName[i]+"Id";
			var get_catagory = waeparams.getContentProviderPersistence(catagoryName[i] , main_hosturl);
			document.getElementById(iid).value = get_catagory;
		}	
	}else{
		document.getElementById('MainhostIdNew').innerHTML = '';	
	}

}

function  changeHostUrl(){
	return;
	var sear_stt = prompt("请输入服务器地址:");
	if(sear_stt){
		
		saveSeverUrl(sear_stt);
		
	}	
}

//按那三个 按钮换服务器
function saveSeverUrl(sear_stt){
	
	if(sear_stt=="ott"||sear_stt=="sh"||sear_stt=="bo"||sear_stt=="angel"||sear_stt=="j"||sear_stt=="hotel"){
		sear_stt = "http://" + sear_stt + ".tvata.com/"	
	}
	
	document.getElementById('MainhostIdNew').innerHTML = sear_stt;
	waeload();	
}


//增加授权服务
function setLocalboss(){
	try{
		var authUrl = SERVER_URL + 'index.php/api?action=getlocalboss';
		if(!wae_httpobj){
			wae_httpobj = wae.create("Net.HttpClient");
		}
		
		if(!intent_obj){
			intent_obj  = wae.create("Intent");
	
		}
		
		var auth_con = wae_httpobj.getWithSync(authUrl).toLocaleString();
		eval("authContent="+auth_con);
		var auth_url = authContent.auth_url; 
		
		if(!netManager_obj){
			netManager_obj = wae.create("Net.NetworkManager")
		}
		
		var netManager = netManager_obj.getNetInfo();
		var macnumber = netManager.match(/MAC:[\s\S]*?,/)[0].replace(/MAC:|,/g,'').replace(/:| /g,'');
		macnumber = 'm' + macnumber;
		var licensereg_url = auth_url + '/index.php/api/licensereg?device='+macnumber;
		intent_obj.startBrowser(licensereg_url) ;

		
		
	}catch(e){
		alert("激活失败 请联系:sales@tvata.com");
	}
}


